"""
@author: 江同学呀
@file: base_alias.py
@date: 2024/2/9 1:18
@desc:
"""
from typing import Union, Type


class BaseAlias:
    """
    别名基类
    """
    _instance = None

    alias_name: str = ""
    _name: str = alias_name

    def __init__(self, alias_name: str, *args, **kwargs):
        self.alias_name: str = alias_name
        return

    def __new__(cls, single: bool = True, *args, **kwargs):
        if single:
            if not isinstance(cls._instance, cls):
                cls._instance = super().__new__(cls)
            return cls._instance
        return super().__new__(cls)

    def __str__(self):
        return self.alias_name

    def __repr__(self):
        return f"<{self.__class__.__name__} alias_name={self.alias_name} object at {id(self)}>"

    # def __or__(self, other: Union["BaseAlias", Type["BaseAlias"]]):
    #     return

    def __init_subclass__(cls, **kwargs):
        """
        子类被声明完时调用
        :param kwargs:
        :return:
        """
        cls._name = cls.alias_name
        return


class Alias(BaseAlias):

    def __new__(cls, *args, **kwargs):
        return super().__new__(cls, single=False, *args, **kwargs)






